summaryrefslogtreecommitdiff
path: root/src/pages/[locale]/news/index.astro
blob: 37e7dd619b6eb45757411bb7aa7e85e59be9238d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
---
import translate from '$i18n/translate';
import tPage from '$i18n/translations/pages/news';
import Page from '$layouts/Page.astro';
import { getLocaleFromPathOrThrow } from '$lib/getLocaleFromPath';
import localeStaticPaths from '$lib/localeStaticPaths';
import { getCollection } from 'astro:content';
import { isNewsItemInLocale } from '$lib/newsUtils';
import NewsIndex from '$components/NewsIndex/NewsIndex.astro';

const allNews = await getCollection('news');
const locale = getLocaleFromPathOrThrow(Astro.url.pathname);
const allNewsInLocale = allNews.filter((item) => isNewsItemInLocale(item, locale));
const t = translate(locale);

export async function getStaticPaths() {
  return localeStaticPaths;
}
---

<Page title={t(tPage, { key: 'title' })}>
  <section>
    <h1>{t(tPage, { key: 'title' })}</h1>
    <NewsIndex newsItems={allNewsInLocale} headingLevel="h2" />
  </section>
</Page>